package com.alibaba.otter.manager.web.config.filter;

import jakarta.servlet.Filter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration(proxyBeanMethods = false)
public class FilterConfiguration {



    /**
     *  order setting reference {@link org.springframework.boot.autoconfigure.security.SecurityProperties#DEFAULT_FILTER_ORDER}
     */
    @Bean
    public FilterRegistrationBean<Filter> requestAccessFilterBean(){

        FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>(new RequestAccessFilter());
        // 此处设置需小于安全拦截器值
        registrationBean.setOrder(-110);
        return registrationBean;
    }

    @Bean
    @ConditionalOnMissingBean
    public FilterRegistrationBean<Filter> loginAuthenticationFilter() {
        // 此处设置需小于安全拦截器值
        return new FilterRegistrationBean<>(new DefaultLoginAuthenticationFilter());
    }

}
